<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>详细内容</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <%--<link rel="stylesheet" href="${newframe}/css/common.css" type="text/css">--%>
    <link rel="stylesheet" href="${newframe}/css/select2.min.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/department/addDepartment.css">
    <!--[if IE 8]>
    <meta http-equiv="X-UA-Compatible"content="IE=EmulateIE7">
    <![endif]-->
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${newframe}/js/select2.full.zh.js"></script>
    <style>
        .clearfix input{
            text-indent:1em
        }
        .btn{
            width:100px;
            line-height:15px;
            background:#35acfd;
            color:white;
        }
        .defualt{
            border:1px solid red !important;
        }
        #myForm{
            height:auto !important;
        }
        label{
            margin-top:5px !important;
        }
    </style>
    <script>
        //关闭并刷新
        function closeFrame(){
            window.parent.closeModal();
        }

    </script>
</head>
<body style="width: 98%">
<div class="header">
    <h1>111</h1>
</div>
<form id="myForm" class="form-horizontal" method="post" >
    <div class="clearfix">
        <div class="form-group mg">
            <label class="control-label">医院名称</label>
            <input type="text" id="hospitalName" name="hospitalName" class="form-control" placeholder="请输入内容">
        </div>
        <div class="form-group">
            <label class="control-label">医院地址</label>
            <input type="text" id="address" name="address" class="form-control" placeholder="请输入内容">
        </div>
        <div class="form-group">
            <label class="control-label">医院编码</label>
            <input type="text" id="hospitalCode" name="hospitalCode" class="form-control" placeholder="请输入内容">
        </div>
        <div class="form-group" style="margin-left:28px;">
            <label class="control-label">登录名</label>
            <input type="text" id="loginName" name="loginName" class="form-control" placeholder="请输入内容">
        </div>
        <div class="form-group">
            <label class="control-label">密码</label>
            <input type="text" id="password" name="password" class="form-control" placeholder="请输入内容">
        </div>
        <div class="form-group" style="margin-left:28px;">
            <label class="control-label">分区</label>
            <input type="text" id="partition" name="partition" class="form-control" placeholder="请输入内容">
        </div>
    </div>
</form>
<div style="width:228px;margin:30px auto;">
    <button type="button" class="btn" data-dismiss="modal" id="closeModalButt" onclick="closeFrame()">关闭</button>
    <button type="btn" class="btn" onclick="save()" style="margin-left:20px;">保存</button>
</div>
<script>
    // 初始化显示数值
    var id = ''
    var refreshto = ''
    $(document).ready(function(){
        // 获取 method
        var url = location.search;
        if( url.indexOf("&") != -1){
            $('.header h1').text('报告单修改')
            var href = decodeURI(decodeURI(location.search))
            console.log(href)
            id = href.split('?')[1].split('&')[0].split('=')[1]
            $('#hospitalName').val(href.split('?')[1].split('&')[3].split('=')[1])
            $('#hospitalCode').val(href.split('?')[1].split('&')[2].split('=')[1])
            $('#address').val(href.split('?')[1].split('&')[4].split('=')[1])
            $('#password').val(href.split('?')[1].split('&')[5].split('=')[1])
            $('#loginName').val(href.split('?')[1].split('&')[6].split('=')[1])
            $('#partition').val(href.split('?')[1].split('&')[7].split('=')[1])
        }else{
            $('.header h1').text('报告单新增')
        }
        $.ajax({
            url:"${URL_SCREENING_GETBREADLINE}",
            dataType:'json',
            type:'post',
            success:function(data){
                urlLib = JSON.parse(data.data)
                refreshto = urlLib[urlLib.length-1].href
            }
        })
    })
    function save(){
        var url = location.search;
        if( url.indexOf("&") != -1){
            if( $('#hospitalCode').val() === '' || $('#hospitalName').val() === "" || $('#address').val() === "" ||
                $('#password').val() === "" || $('#loginName').val() === "" || $('#partition').val() === "" ){
                let inputs = $('input')
                for( let a = 0; a < inputs.length; a++ ){
                    if( $(inputs[a]).val() === "" ){
                        $(inputs[a]).addClass('defualt')
                    }else{
                        if( $(inputs[a]).hasClass('defualt') ){
                            $(inputs[a]).removeClass('defualt')
                        }
                    }
                }
            }else{
                $.ajax({
                    url:"${URL_WHOSPITAL_UPDATE}",
                    data:{
                        id:parseInt(id),
                        hospitalCode:$('#hospitalCode').val(),
                        hospitalName:$('#hospitalName').val(),
                        address:$('#address').val(),
                        password:$('#password').val(),
                        loginName:$('#loginName').val(),
                        partition:$('#partition').val()
                    },
                    dataType:"json",
                    type:"post",
                    success:function(data){
                        if(data.success){
                            parent.showSrc(refreshto)
                            closeFrame()
                        }
                    }
                })
            }
        }else{
            if( $('#hospitalCode').val() === '' || $('#hospitalName').val() === "" || $('#address').val() === "" ||
                $('#password').val() === "" || $('#loginName').val() === "" || $('#partition').val() === "" ){
                let inputs = $('input')
                for( let a = 0; a < inputs.length; a++ ){
                    if( $(inputs[a]).val() === "" ){
                        $(inputs[a]).addClass('defualt')
                    }else{
                        if( $(inputs[a]).hasClass('defualt') ){
                            $(inputs[a]).removeClass('defualt')
                        }
                    }
                }
            }else{
                $.ajax({
                    url:"${URL_WHOSPITAL_SAVE}",
                    data:{
                        hospitalCode:$('#hospitalCode').val(),
                        hospitalName:$('#hospitalName').val(),
                        address:$('#address').val(),
                        password:$('#password').val(),
                        loginName:$('#loginName').val(),
                        partition:$('#partition').val()
                    },
                    dataType:"json",
                    type:"post",
                    success:function(data){
                        console.log(data)
                        closeFrame()
                    }
                })
            }
        }
    }
</script>
</body>
</html>
